package com.dly.blog.controller;

import com.dly.blog.domain.ro.menu.UpdateRoleMenuRO;
import com.dly.blog.domain.ro.permission.UpdateRolePermissionRO;
import com.dly.blog.domain.ro.role.HomePageRO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dly.blog.controller.BaseController;
import lombok.AllArgsConstructor;
import com.dly.blog.domain.vo.role.RoleVO;
import com.dly.blog.domain.ro.role.RolePageRO;
import com.dly.blog.domain.ro.role.RoleAddRO;
import com.dly.blog.domain.ro.role.RoleEditRO;
import com.dly.blog.service.RoleService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.dly.blog.domain.vo.PageVO;
import com.dly.blog.msg.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author DLY
 * @since 2024-11-11 10:59:37
 */
@Tag(name = "角色相关")
@AllArgsConstructor
@RestController
@RequestMapping("/user/role")
public class RoleController extends BaseController {

    private final RoleService roleService;

    @GetMapping(value = "/permission_all")
    @Operation(summary = "获取角色的权限")
    public ResponseEntity<R<List<String>>> getRolePermission(@RequestParam String roleId){
        return operate(()-> this.successDate(roleService.getRolePermission(roleId)));
    }

    @PostMapping(value = "/permission_update")
    @Operation(summary = "更新角色的权限")
    public ResponseEntity<R<Void>> updateRolePermission(@RequestBody UpdateRolePermissionRO updateRolePermissionRO){
        roleService.updateRolePermission(updateRolePermissionRO);
        return operate(this::success);
    }

    @GetMapping(value = "/home_page")
    @Operation(summary = "获取角色的首页菜单")
    public ResponseEntity<R<String>> getHomePage(@RequestParam String roleId){
        return operate(()-> this.successDate(roleService.getHomePage(roleId)));
    }

    @PostMapping(value = "/set_home_page")
    @Operation(summary = "设置角色的首页菜单")
    public ResponseEntity<R<Void>> setHomePage(@RequestBody HomePageRO homePageRO){
        roleService.setHomePage(homePageRO);
        return operate(this::success);

    }

    @GetMapping(value = "/menu_all")
    @Operation(summary = "获取角色的菜单")
    public ResponseEntity<R<List<String>>> getRoleMenu(@RequestParam String roleId){
        return operate(()-> this.successDate(roleService.getRoleMenu(roleId)));
    }

    @PostMapping(value = "/menu_update")
    @Operation(summary = "更新菜单的权限")
    public ResponseEntity<R<Void>> updateRoleMenu(@RequestBody UpdateRoleMenuRO updateRoleMenuRO){
        roleService.updateRoleMenu(updateRoleMenuRO);
        return operate(this::success);
    }


    @GetMapping(value = "/getAll")
    @Operation(summary = "获取所有角色信息")
    public ResponseEntity<R<List<RoleVO>>> getRoleAll(){
        return operate(()-> this.successDate(roleService.getRoleAll()));
    }


    @PostMapping(value = "/page")
    @Operation(summary = "分页获取角色信息")
    public ResponseEntity<R<PageVO<RoleVO>>> getRolePage(@RequestBody RolePageRO rolePageRO){
        return operate(()-> this.successDate(roleService.getRolePage(rolePageRO)));
    }

    @PostMapping(value = "/add")
    @Operation(summary = "添加角色信息")
    public ResponseEntity<R<Void>> addRole(@RequestBody RoleAddRO roleAddRO){
        roleService.addRole(roleAddRO);
        return operate(this::success);
    }

    @PostMapping(value = "/edit")
    @Operation(summary = "修改角色信息")
    public ResponseEntity<R<Void>> editRole(@RequestBody RoleEditRO roleEditRO){
        roleService.editRole(roleEditRO);
        return operate(this::success);
    }

    @PostMapping(value = "/get/{id}")
    @Operation(summary = "获取角色信息")
    public ResponseEntity<R<RoleVO>> getRole(@PathVariable(value = "id") String id){
        return operate(()-> this.successDate(roleService.getRole(id)));
    }

    @PostMapping(value = "/remove/{ids}")
    @Operation(summary = "删除角色信息")
    public ResponseEntity<R<Void>> removeRole(@PathVariable(value = "ids") String[] ids){
        roleService.removeRole(ids);
        return operate(this::success);
    }

}
